home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 23 / Amiga Format AFCD23 (Feb 1998, Issue 107).iso / -in_the_mag- / emulation / consoles / amigavgb / listall.c < prev    next >
C/C++ Source or Header  |  1997-12-12  |  2KB  |  60 lines

  1. /** GameBoy Cartridge Lister *********************************/
  2. /**                                                         **/
  3. /**                        listall.c                        **/
  4. /**                                                         **/
  5. /** This program written by Pascal Felber will list all of  **/
  6. /** your cartridges making a list of internal names         **/
  7. /** contained in them.                                      **/
  8. /**                                                         **/
  9. /** Copyright (C) Pascal Felber 1996                        **/
  10. /**     You are not allowed to distribute this software     **/
  11. /**     commercially. Please, notify me, if you make any    **/   
  12. /**     changes to this file.                               **/
  13. /*************************************************************/
  14.  
  15. #include <stdio.h>
  16. #include <sys/stat.h>
  17.  
  18. #define NAMEFIELD 20
  19.  
  20. char HDR[0x150];
  21.  
  22. void main(int argc,char *argv[])
  23. {
  24.   FILE *s;
  25.   struct stat st;
  26.   int arg, i;
  27.  
  28.   if(argc < 2) {
  29.     fprintf(stderr, "Usage: %s files...\n", argv[0]);
  30.     exit(1);
  31.   }
  32.  
  33.   printf("+---------------------+---------+---------\n");
  34.   printf("| FileName            | Size    | CartName\n");
  35.   printf("+---------------------+---------+---------\n");
  36.   for(arg = 1; arg < argc; arg++) {
  37.     if(!(s = fopen(argv[arg], "rb"))) {
  38.       perror("fopen");
  39.       exit(1);
  40.     }
  41.     if(stat(argv[arg], &st)) {
  42.       perror("fstat");
  43.       exit(1);
  44.     }
  45.     if(fread(HDR, 1, 0x150, s) != 0x150) {
  46.       perror("fread");
  47.       exit(1);
  48.     }
  49.     HDR[0x146] = '\0';
  50.     printf("| %s", &HDR[0x134]);
  51.     for(i = strlen(&HDR[0x134]); i < NAMEFIELD; i++)
  52.       putchar(' ');
  53.     printf("| %7d | ", st.st_size);
  54.     printf("%s", argv[arg]);
  55.     putchar('\n');
  56.     fclose(s);
  57.   }
  58.   printf("+---------------------+---------+---------\n");
  59. }
  60.